package com.sanyuan.cloud.module.system.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: RedissonConfig
 * @Author: wuyuwei
 * @Date: 2025/4/8
 */
@Configuration
public class RedissonConfig {

    @Value("${nongmo.redis.host}")
    private String host;
    @Value("${nongmo.redis.password}")
    private String password;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        // 单机模式
        config.useSingleServer()
                .setAddress(host)
                .setPassword(password)
                .setConnectionMinimumIdleSize(10)
                .setConnectionPoolSize(64)
                .setConnectTimeout(5000)
                .setTimeout(3000)
                .setRetryAttempts(3)
                .setRetryInterval(1500);

        // 设置线程池大小
        config.setThreads(16);
        config.setNettyThreads(32);

        // 设置序列化方式
        config.setCodec(new org.redisson.codec.KryoCodec());

        return Redisson.create(config);
    }
}
